<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import = "ServiceImpl.CarServiceImpl" %>
<%@ page import = "ServiceImpl.UserServiceImpl" %>
<%@ page import = "Bean.Car" %>
<%@ page import = "Bean.User" %>
<%@ page import = "Bean.UserAndCar" %>
<%@ page import = "java.util.List" %>
<%@ page import = "java.util.ArrayList" %>
<%@ page import = "ServiceImpl.UserCarServiceImpl" %>
<%@ page import = "java.util.ArrayList" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert title here</title>
<link type="text/css" href="assets/css/bootstrap.min.css" rel="stylesheet">
<script src="assets/js/jquery-3.2.1.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
</head>
<body>
<jsp:include page="nav.jsp"/>
<div class="container-fluid">
    <div class="row">
      <div class="btn-wrap">
    <div class="btn-group btn-group-justified">
       
        	<a href="#" class="btn btn-default active" target="test">车牌总览</a>
            <div class="btn-group">
		      <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button">车辆信息管理<span class="caret"></span></button>
			    <ul class="dropdown-menu">
			        <li><a href="add_car_info.jsp">添加车辆信息</a></li>
			        <li><a href="select_car_info.jsp">查询车辆信息</a></li>
			    </ul>
		  	</div>
		  	<div class="btn-group">
		      <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button">用户信息管理<span class="caret"></span></button>
			    <ul class="dropdown-menu">
			        <li><a href="add_user.jsp">添加用户信息</a></li>
			        <li><a href="select_user.jsp">查询用户信息</a></li>
			    </ul>
		  	</div>
		  	<div class="btn-group">
		      <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button">通勤信息管理<span class="caret"></span></button>
			    <ul class="dropdown-menu">
			        <li><a href="add_info_of_car.jsp">添加通勤信息</a></li>
			        <li><a href="select_info_of_car.jsp">查询通勤信息</a></li>
			    </ul>
		  	</div>
    </div>
</div>

      <div class="col-md-9">
	<!-- <form action = "login.jsp" method = "post"> 
			<input type = "submit" value = "退出登录" />
	</form> -->
	
	<!-- <form action="add_car_info.jsp">
		<input type = "submit" value = "添加车辆信息"/>
	</form>
	
	<form action="select_car_info.jsp">
		<input type = "submit" value = "查询车辆信息"/>
	</form>
	<form action="add_user.jsp">
		<input type = "submit" value = "添加用户信息"/>
	</form>
	
	<form action="select_user.jsp">
		<input type = "submit" value = "查询用户信息"/>
	</form>
	
	<form action="add_info_of_car.jsp">
		<input type = "submit" value = "添加通勤信息"/>
	</form>
	
	<form action="select_info_of_car.jsp">
		<input type = "submit" value = "查询通勤信息"/>
	</form> -->
	
	<%
		// java 语句把所有用户的所有车辆给他遍历一遍
		// 用几个变量存储起来
		/*
		UserServiceImpl userServiceImpl = new UserServiceImpl();
		UserCarServiceImpl userCarServiceImpl = new UserCarServiceImpl();
		List<User> myUserList = userServiceImpl.selectAllUser();
		List<List<Car>> userCars = new ArrayList<List<Car>>();
		List<Integer> userCarsNum = new ArrayList<Integer>();
		// userCars 是一个包含列表的列表
		for(User user : myUserList) {
			// cars 是一个车对象的列表
			List<Car> cars = userCarServiceImpl.selectAllCarOfUser(user.getUsername());
			userCars.add(cars); 
			userCarsNum.add(cars.size());
		}
		pageContext.setAttribute("users", myUserList);
		pageContext.setAttribute("user_cars_num", userCarsNum);
		*/
		UserServiceImpl userServiceImpl = new UserServiceImpl();
		UserCarServiceImpl userCarServiceImpl = new UserCarServiceImpl();
		List<User> allUsers = userServiceImpl.selectAllUser();
		List<List<UserAndCar>> list = new ArrayList<List<UserAndCar>>();
		for(User user : allUsers) {
			List<UserAndCar> tmp = userCarServiceImpl.selectAllCarOfUser(user.getUsername());
			list.add(tmp);
		}
		pageContext.setAttribute("list", list);
	%>

	<table border = "3" >
		<tr>
			<th> 用户 </th>
			<th> 车牌 </th>
		</tr>
		<c:forEach items = "${ list }" var = "tmp">
			<c:forEach items = "${ tmp }" var = "t">
				<tr>
					<td>
						${ t.username }
					</td>
					<td>
						${ t.car_id }
					</td>
				</tr>
			</c:forEach>
		</c:forEach>	 
	</table>
	      </div>
    </div>
  </div>
</body>
</html>